package com.xncoding.freemarker.utile;

import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;

public class CommonsFileUtilsFile {

    public static void main(String[] args) {
        test();
    }

    public static void test(){
        File sourceFile = new File("/Users/ligang/Desktop/desk/111.txt");
        File targetFile = new File("/Users/ligang/Desktop/desk/target.txt");

        try {
            // 复制文件
            FileUtils.copyFile(sourceFile, targetFile);
            System.out.println("File copied successfully!");

            // 读取文件内容
            String content = FileUtils.readFileToString(sourceFile, "UTF-8");
            System.out.println("File content: " + content);

            // 删除文件
            FileUtils.deleteQuietly(targetFile);
            System.out.println("File deleted successfully!");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
